var nr = document.querySelectorAll(".nr");
var text = document.querySelectorAll(".text");
var sp = document.querySelectorAll(".sp");
var ca = document.querySelectorAll(".delete");
var to = document.querySelector(".to");
var sp1 = document.querySelector(".sp1");

/*for (let i = 0; i < 5; i++){
    /!*text[i].addEventListener("change",function(){
        var num = nr[i].innerHTML * text[i].value;
        sp[i].innerHTML = num;
    });*!/
    ca[i].addEventListener("click",function(){
        to.removeChild(this.parentNode)
    });
}*/
var sum = 0;
for (let p = 0; p < text.length; p++){
    var t = sp[p].innerHTML;
    t = Number(t);
    console.log(t);
    sum += t;
    console.log(sum);
    text[p].addEventListener("change",function(){
        var num = nr[p].innerHTML * text[p].value;
        num = num.toFixed(2);
        sp[p].innerHTML = num;
        sum += Number(sp[p].innerHTML) - Number(nr[p].innerHTML);
        sp1.innerHTML = sum;

    });
    ca[p].addEventListener("click",function(){
        to.removeChild(this.parentNode)
    });
}
/*var a = sp[0].innerHTML;
var b = sp[1].innerHTML;
var c = sp[2].innerHTML;
var d = sp[3].innerHTML;
var f = sp[4].innerHTML;
a = Number(a);
b = Number(b);
c = Number(c);
d = Number(d);
f = Number(f);
var sum = a + b + c + d + f;*/













/*
sp1.addEventListener('change',function(){
   sp1.innerHTML = sp[0] + sp[1] + sp[2] + sp[3] + sp[4]
}
*/

/*
text[0].addEventListener("change",function(){
    var num = nr[0].innerHTML * text[0].value;
    sp[0].innerHTML = num;
});*/
